package com.spirng.leetcode.day06;

import java.util.LinkedList;
import java.util.Queue;

public class Test104 {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(1,new TreeNode(2,new TreeNode(4,new TreeNode(8),null),new TreeNode(5)),new TreeNode(3,new TreeNode(6),null
        ));
        Test104 test104 = new Test104();
        int i1 = test104.maxDepth2(root);
    }
    public int maxDepth(TreeNode root) {
        Queue<TreeNode> queue=new LinkedList<>();
        int sum=0;
        queue.offer(root);
        while (!queue.isEmpty()){
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                TreeNode node = queue.remove();
                if(node.left!=null) queue.add(node.left);
                if(node.right!=null) queue.add(node.right);
            }
            sum++;
        }
        return sum;
    }
    public int maxDepth2(TreeNode root) {
        if(root==null){
            return 0;
        }
        int m=maxDepth2(root.left);
        int n=maxDepth2(root.right);
//        int result=Math.abs(m-n)+1;
        int result=Math.max(m,n)+1;
        return result;
    }

}
